<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>文章栏目列表</title> 
    <link rel="shortcut icon" href="favicon.ico"> 
    <link href="/public/admin/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="/public/admin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="/public/admin/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="/public/admin/css/animate.css" rel="stylesheet">
    <link href="/public/admin/css/style.css?v=4.0.0" rel="stylesheet">
    <link href="/public/admin/css/ratuo.css" rel="stylesheet">

    <!-- 全局js -->
    <script src="/public/admin/js/jquery.min.js?v=2.1.4"></script>
    <script src="/public/admin/js/bootstrap.min.js?v=3.3.5"></script>

    <!-- 自定义js -->
    <script src="/public/admin/js/content.js?v=1.0.0"></script>
    <script src="/public/admin/js/contabs.js"></script>
    <script src="/public/admin/js/common.js"></script>
    <script src="/public/admin/js/plugins/layer/layer.min.js"></script>
    <script src="/public/admin/js/article.js"></script>
    <script src="/public/admin/js/myAjax.js"></script>

    <!-- Bootstrap table -->
    <script src="/public/admin/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
    <script src="/public/admin/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
    <script src="/public/admin/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>

    <base target="_blank">
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>文章列表</h5>
                </div>
                <div class="ibox-content">
                    <div class="row">
                        <div class="col-xs-12">
                            <div class="box">
                                <div class="box-header">
                                  <div class="panel-body">
                                      <a onclick="window.location.href=location.href;" href="javascript:;" class="btn btn-primary pull-left" style="margin-right: 10px;"><i class="glyphicon glyphicon-refresh"></i>刷新</a>
                                      <a onclick="openYemian('/index.php/Admin/Article/category','添加文章栏目')" href="javascript:;" class="btn btn-primary pull-left" target="_self"><i class="fa fa-plus"></i>新增分类</a>
                                  </div>                  
                                </div><!-- /.box-header -->
                                <div class="box-body">
                                    <div class="row">
                                        <div class="col-sm-12">
                                            <table id="list-table" class="table table-bordered table-hover">
                                                <thead>
                                                    <tr role="row">
                                                        <th>栏目ID</th>
                                                        <th>栏目名称</th>
                                                        <th>显示</th>
                                                        <th>排序</th>
                                                        <th>操作</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                {if empty($cat_list)}
                                                    <tr><td colspan="6" style="text-align:center;">暂无数据</td></tr>
                                                {/if}
                                                {foreach name="cat_list" item="vo" key="k" }
                                                  <tr role="row" class="{$vo.level}" id="{$vo.level}_{$vo.kind_id}">
                                                    <td>{$vo.kind_id}</td>

                                                    <td class="sorting_1" align="left" style="padding-left:<?php echo ($vo['level'] * 4); ?>em"> 
                                                    {if $vo.is_leaf <> 1}
                                                        <span class="glyphicon glyphicon-minus btn-warning" id="icon_{$vo.level}_{$vo.id}" aria-hidden="true" onclick="rowClicked(this)" ></span>&nbsp;                  
                                                    {/if}<span><a style="color:#666;" href="{:url('Home/Index/category',array('kid'=>$vo['kind_id']))}" title="点击预览" target="_block">{$vo.name}</a></span>
                                                    </td>

                                                    <td>
                                                        <img width="20" height="20" class="cursor" src="/public/admin/images/{if $vo['is_hide'] <> 1}yes.png{else /}cancel.png{/if}" onclick="changeTableVal('article_kind','kind_id','{$vo.kind_id}','is_hide',this)"/>
                                                    </td>

                                                    <td>                         
                                                      <input type="text" onkeyup="this.value=this.value.replace(/[^\d]/g,'')" onpaste="this.value=this.value.replace(/[^\d]/g,'')" onchange="updateSort('article_kind','kind_id','{$vo.kind_id}','sort_order',this)" size="4" value="{$vo.sort_order}" />
                                                    </td>
                                                    <td style="text-align: left;">
                                                    <a class="btn btn-primary" href="javascript:;" onclick="openYemian('/index.php/Admin/Article/category/act/edit/kind_id/{$vo.kind_id}','编辑文章栏目')" target="_self"><i class="fa fa-pencil"></i></a>
                                                    <a class="btn btn-danger" href="javascript:void(0)" data-url="{:url('Article/categoryHandle')}" data-id="{$vo.kind_id}" onclick="delcategory('确定删除该栏目？',{$vo.kind_id},'/index.php/Admin/Article/categoryHandle',$(this))"><i class="fa fa-trash-o"></i></a>

                                                    </td>
                                                  </tr>
                                                {/foreach}
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                </div><!-- /.box-body -->
                            </div><!-- /.box -->
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div> 
</div>
 
<input id="handle_status" value="" hidden="hidden">

<script type="text/javascript">
     
    // 以下是 bootstrap 自带的  js
    function rowClicked(obj){
        span = obj;

        obj = obj.parentNode.parentNode;

        var tbl = document.getElementById("list-table");

        var lvl = parseInt(obj.className);

        var fnd = false;
      
        var sub_display = $(span).hasClass('glyphicon-minus') ? 'none' : '' ? 'block' : 'table-row' ;
        //console.log(sub_display);
        if(sub_display == 'none'){
            $(span).removeClass('glyphicon-minus btn-info');
            $(span).addClass('glyphicon-plus btn-warning');
        }else{
            $(span).removeClass('glyphicon-plus btn-info');
            $(span).addClass('glyphicon-minus btn-warning');
        }

        for (i = 0; i < tbl.rows.length; i++){
            var row = tbl.rows[i];
          
            if (row == obj){
                fnd = true;         
            }else{
                if (fnd == true){
                    var cur = parseInt(row.className);
                    var icon = 'icon_' + row.id;
                    if (cur > lvl){
                        row.style.display = sub_display;
                        if (sub_display != 'none'){
                            var iconimg = document.getElementById(icon);
                            $(iconimg).removeClass('glyphicon-plus btn-info');
                            $(iconimg).addClass('glyphicon-minus btn-warning');
                        }else{                    
                            $(iconimg).removeClass('glyphicon-minus btn-info');
                            $(iconimg).addClass('glyphicon-plus btn-warning');
                        }
                    }else{
                        fnd = false;
                        break;
                    }
              }
            }
        }

        for (i = 0; i < obj.cells[0].childNodes.length; i++){
            var imgObj = obj.cells[0].childNodes[i];
            if (imgObj.tagName == "IMG"){
                if($(imgObj).hasClass('glyphicon-plus btn-info')){
                    $(imgObj).removeClass('glyphicon-plus btn-info');
                    $(imgObj).addClass('glyphicon-minus btn-warning');
                }else{
                    $(imgObj).removeClass('glyphicon-minus btn-warning');
                    $(imgObj).addClass('glyphicon-plus btn-info');
                }
            }
        }

    }

    function delfun(obj){
        if(confirm('确认删除')){        
            $.ajax({
                type : 'post',
                url : $(obj).attr('data-url'),
                data : {act:'del',cat_id:$(obj).attr('data-id')},
                dataType : 'json',
                success : function(data){
                    if(data==1){
                        $(obj).parent().parent().remove();
                    }else{
                        layer.alert(data, {icon: 2});  //alert(data);
                    }
                }
            })
        }
        return false;
    }

    function delcategory(name,id,url,obj) {
        top.layer.confirm(name,{
            icon:3,
            btn:['确定','取消'],
        } , function(){
            $.ajax({
                url : url,
                type : "post",
                data : {kind_id:id,act:'del'},
                dataType : "json",
                success:function(data){
                    if (data.status == 0) { 
                        top.layer.msg(data.message);
                    } else {
                        top.layer.msg(data.message);
                        $(obj).parent().parent().remove();
                    }
                }
            });
        } , function(){
            layer.close(); //再执行关闭 
        })
    }
</script>

</body>
</html>